package com.pkangu.nolattosio;

import java.util.ArrayList;

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;

import com.pkangu.nolattosio.database.DatabaseAdapter;
import com.pkangu.nolattosio.database.Metadata.Comuni;

public class HomeActivity extends Activity {
	//AutocompleteTextview declarations
	private AutoCompleteTextView actxt;
	private DatabaseAdapter dbAdapter;
	private Cursor cursor;
	ArrayList<String> arrList;
	ArrayAdapter<String> arrAdapter;
	
	//other declarations
	private Button btn_send;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_home);
		//AutocompleteTextview stuff
		dbAdapter = new DatabaseAdapter(getApplicationContext());
		arrList = new ArrayList<String>();
		actxt = (AutoCompleteTextView) findViewById(R.id.actxt_locazione);
		dbAdapter.open();
		cursor = dbAdapter.fetchStocazzo();
		cursor.moveToFirst();
		for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
			arrList.add(cursor.getString(cursor.getColumnIndex(Comuni.KEY_ID_PROVINCIA)));
		}
		arrAdapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_dropdown_item_1line,arrList);
		actxt.setAdapter(arrAdapter);
		
		actxt.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parentView, View selectedItemView, int position,	long id) {
				
			}
			
		});
		
		
		//other stuffs
		btn_send = (Button) findViewById(R.id.btn_luogo);
		btn_send.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.home, menu);
		return true;
	}

}
